<?php $this->placeholder('container-class')->set('post_ad maid')?>

<?php $this->JQuery()->javascriptCaptureStart()?>
$j(document).ready(function() {
    $j.datepicker.setDefaults($.datepicker.regional[ "<?php echo $this->current_language == 'en' ? 'zh-HK' : 'zh-HK'?>" ]);
});

$j(document).ready(function() {
	//remove extra option in visa
	$j("#visastatus option[value='5']").remove();
	$j("#visastatus option[value='6']").remove();
	
    $j('#add_more_btn').click(function() {
        if ($j('#add_more_checkbox').attr('value') == 1) {
            $j('#add_more_checkbox').attr('value',0);
        }
        else {
            $j('#add_more_checkbox').attr('value',1);
        }
        $j('#add_more').toggle();
        return false;
    });

    if ($j('#add_more_checkbox').attr('value') == 0) {
        $j('#add_more').show();
    }
    else {
        $j('#add_more').hide();
    }

    // Control for Title
    $j('input#title').keydown(function(event) {
        var charLength = 100 - $j(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $j('span#counter_title').html('<em>'+charLength + '</em> <?php echo $this->t('characters remaining')?>');
        }
    });
    if ($.browser.msie) {
       // $('#ui-datepicker-div').remove();
    }

    // Control for reason leaving previous job
    $('textarea#reasonleavingpreviousjob').keydown(function(event) {
        var charLength = 3000 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_previous_job').html('<em>'+charLength + '</em> <?php echo $this->t('characters remaining')?>');
        }
    });


    // Control for reason leaving previous job
    $('textarea#previous_employers').keydown(function(event) {
        var charLength = 3000 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_previous_employer').html('<em>'+charLength + '</em> <?php echo $this->t('characters remaining')?>');
        }
    });    
    
    

    // Control for description
    $('textarea#description').keydown(function(event) {
        var charLength = 3000 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_description').html('<em>'+charLength + '</em> <?php echo $this->t('characters remaining')?>');
        }
    });
    

    <?php 
        $list = Model_Listing_Maid::getLanguagesPostAd();
        $lng  = $list;
        $list = array();

        foreach($lng  as $k => $v) {
                $list[] = array('value' => $k, 'label' => $v);
        }    
    ?>
    var languages_available = <?php echo json_encode($list);?>;
    $j('#languages_auto').autocomplete( "option" , 'source', languages_available);
    $j("#languages_auto" ).autocomplete({ minLength: 0 });
    $j("#languages_auto" ).click(function(e) {            
        e.keyCode = $j.ui.keyCode.DOWN;
        e.type = 'keydown.autocomplete';
        $(this).trigger(e);
        return false;
    });
    $j('#languages_auto').attr('name','');
    
    
    
    $j('#preview_link').click(function() {
        
        var action = $j('#listing_form').attr('action');
        $j('#listing_form').attr('action', '<?php echo $this->preview_link?>');
        $j('#listing_form').attr('target','_blank');
        $j('#listing_form').submit();
        $j('#listing_form').attr('action', action);
        $j('#listing_form').attr('target','_self');
        return false;
    });
});
<?php $this->JQuery()->javascriptCaptureEnd()?>

<form action="<?php echo $this->escape($this->form->getAction()) ?>" method="<?php echo $this->escape($this->form->getMethod())?>" id="listing_form"  enctype="multipart/form-data">
    <fieldset>
        <legend><?php echo $this->t('Create Your Ad');?></legend>
        <div class="required"><?php echo $this->t('Required Information')?></div>
		<div class="desc">
			<?php if( $this->current_language == 'tc'): ?>
			<p><?php echo $this->t('If you want to publish ads in English, please <a href="'.$this->url_en.'">click here</a> to fill out.');?></p>
			<?php else: ?>
			<p><?php echo $this->t('如果你想刊登中文廣告, 請<a href="'.$this->url_tc.'">按此</a>填寫.');?></p>
			<?php endif; ?>
		</div>
        <div class="category desc">
              <label><?php echo $this->t('Selected Categories')?>
                  <?php /*if (!isset($_GET['id'])):?>
                    (<a href="<?php echo $this->geturl('post-an-ad', 'listing', null, null, array('category' => $_GET['category'], 'change' => 1))?>">Change</a>)
                  <?php endif;*/?>
                  :
              </label>
              <ul>
                  <?php foreach($this->category as $cat):?>
                      <li>
                          <?php
                            $tmp = array();
                            foreach($cat->getParentTree() as $p) {
                                $tmp[] = $p->name;
                            }
                            echo implode(' &gt; ', $tmp);
                          ?>
                      </li>
                  <?php endforeach;?>
             </ul>
        </div>
        <input type="hidden" name="adid" id="adid" value="<?php echo $this->adid?>">
        <?php foreach($this->category as $cat):?>
            <input type="hidden" name="category[]" value="<?php echo $cat->_id?>">
        <?php endforeach;?>

        <div class="title text">
              <label class="required"><?php echo $this->t('Title')?></label>
              <span id="counter_title"><?php echo $this->t('<em>100</em> characters remaining')?></span>
              <?php echo $this->form->tl_en ?>
              <?php if (!empty($_POST['tl_en'])) { ?>
              <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['tl_en'])) { ?>
                  <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
              <?php } } ?>
        </div>

        <div class="custom_info">
            <div class="custom_info_1">
                <div class="age text">
                    <label class="required"><?php echo $this->t('Date of Birth')?></label><span>e.g. 24/12/2011</span>
                    <?php echo $this->form->dateofbirth ?>
                </div>
                <div class="education select">
                    <label class="required"><?php echo $this->t('Education')?></label>
                    <?php echo $this->form->education ?>
                </div>
                <div class="languages text auto">
                  <label class="required"><?php echo $this->t('Languages')?></label><span class="hint"><?php echo $this->t('You can add multiple languages.')?></span>
                  <?php echo $this->form->languages_auto ?>
                  <?php
                    if (!empty($this->listing->languages) && empty($_POST['languages'])) {
                        $_POST['languages'] = $this->listing->languages;
                    }
                  ?>

                  <p id="lng_cnt">
                      <span><?php echo $this->t('Selected Languages:')?> </span>
                      <?php if (!empty($_POST['languages'])):?>
                          <?php $lng = Model_Listing_Maid::getLanguagesPostAd();?>
                          <?php $to_add = '';?>
                          <?php foreach((array)$_POST['languages'] as $v):?>
                              <?php if (!empty($lng[$v])) :?>
                                  <input type="hidden" name="languages[]" value="<?php echo $v?>" class="lng_<?php echo $v?>">
                                  <span class="tag lng_<?php echo $v?>"><?php echo $to_add.$lng[$v]?>
                                        <a id="<?php echo $v?>" class="remove lng_<?php echo $v?>">(<?php echo $this->t('Remove')?>)</a>
                                  </span>
                                  <?php unset($lng[$v])?>
                              <?php endif;?>
                              <?php $to_add = ', ';?>
                          <?php endforeach;?>
                      <?php endif;?>                  
                  </p>
                </div>
                <div class="nationality select">
                    <label class="required"><?php echo $this->t('Nationality')?></label>
                    <?php echo $this->form->nationality ?>
                </div>
                <div class="religion select">
                    <label class="required"><?php echo $this->t('Religion')?></label>
                    <?php echo $this->form->religion ?>
                </div>
                <div class="maritalstatus select">
                    <label class="required"><?php echo $this->t('Marital Status')?></label>
                    <?php echo $this->form->maritalstatus ?>
                </div>           
                <div class="contact_number text">
                    <label class="required"><?php echo $this->t('Contact Number')?></label>
                    <span class="hint"><?php echo $this->t('e.g. 12345678')?></span>
                    <?php echo $this->form->contact_number?>
                    <?php
                        $errors = $this->form->contact_number->getMessages();
                    ?>
                    <?php if(!empty($errors)):?>
                        <?php echo $this->formErrors($errors);?>
                    <?php endif;?>
                </div>              
                
                <div class="text">
                    <label><?php echo $this->t('Salary per Month (Numbers only)')?></label>
					<span class="hint"><?php echo $this->t('e.g. 4000');?></span>
                    <span class="desc_text">
						<?php echo $this->t('HKD')?>
						<?php echo $this->form->salary ?>
					</span>
                    
                    <?php
                        $errors = $this->form->salary->getMessages();
                    ?>
                    <?php if(!empty($errors)):?>
                        <?php echo $this->formErrors($errors);?>
                    <?php endif;?>
                </div>        
                <!--div class="visastatus select">
                    <label><?php echo $this->t('Visa Status')?></label>
                    <?php echo $this->form->visastatus ?>
                </div-->          
            </div>
            <div class="custom_info_2">
				<div class="visastatus select">
                    <label><?php echo $this->t('Visa Status')?></label>
                    <?php echo $this->form->visastatus ?>
                </div> 
                <!--div class="gender select">
                    <label class="required"><?php echo $this->t('Gender')?></label>
                    <?php echo $this->form->gender ?>
                </div-->
                <div class="radio"> 
			  		<span class="required"><?php echo $this->t('Gender')?></span>
                	<?php echo $this->form->gender ?>
              	</div>
                <div class="availabletostart text">
                    <label class="required"><?php echo $this->t('Available to Start')?></label>
					<span>e.g. 24/12/2011</span>
                    <?php echo $this->form->availabletostart ?>
                </div>
                <div class="radio">
                    <span class="required"><?php echo $this->t('Employment Type')?></span>
                    <?php echo $this->form->employmenttype ?>
                </div>
                <div class="reason textarea">
                    <label class="required"><?php echo $this->t('Reason for Leaving Previous Job')?></label>
                    <span id="counter_previous_job"><?php echo $this->t('<em>3000</em> characters remaining')?></span>
                    <?php echo $this->form->rlj_en?>
                    <?php if (!empty($_POST['rlj_en'])): ?>
                        <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['rlj_en'])): ?>
                          <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
                        <?php endif; ?>
                    <?php endif; ?>
                    <span id="info_description"><?php echo $this->t('To prevent spam, do not enter any email addresses.')?></span>
                </div>
                <div class="reason textarea">
                    <label><?php echo $this->t('Previous Employer References')?></label>
                    <span id="counter_previous_employer"><?php echo $this->t('<em>3000</em> characters remaining')?></span>
                    <?php echo $this->form->pe_en?>
                    <?php if (!empty($_POST['pe_en'])): ?>
                        <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['pe_en'])): ?>
                          <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
                        <?php endif; ?>
                    <?php endif; ?>
                    <span id="info_description"><?php echo $this->t('To prevent spam, do not enter any email addresses.')?></span>
                </div>
            </div>
        </div>

        <div class="add_more optional">
            <h2 class="required"><?php echo $this->t('Overall Skillsets')?></h2>
            <div class="select text">
                <dl>
                    <dt><label class="required"><?php echo $this->t('Cooking Style')?> </label><?php echo $this->t('Skill Level')?></dt>
                    <dd><label><?php echo $this->t('Western')?></label><?php echo $this->form->skilllevelwestern ?></dd>
                    <dd><label><?php echo $this->t('Chinese')?></label><?php echo $this->form->skilllevelchinese ?></dd>
                    <dd>
                        <label><?php echo $this->t('Specialities')?><span>e.g. Italian Style</span></label>
                        <?php echo $this->form->spo_en ?>
                    </dd>
                </dl>      
			</div>
            <div class="select">
                <dl>
                    <dt><label class="required"><?php echo $this->t('People Care and Nursing')?> </label><?php echo $this->t('Years of Experience')?></dt>
                    <dd><label><?php echo $this->t('Newborn Experience')?></label><?php echo $this->form->yearexpnewborn ?></dd>
                    <dd><label><?php echo $this->t('Children Experience')?></label><?php echo $this->form->yearexpchildren ?></dd>
                    <dd><label><?php echo $this->t('Disable Experience')?></label><?php echo $this->form->yearexpdisable ?></dd>
                    <dd><label><?php echo $this->t('Elderly Experience')?></label><?php echo $this->form->yearexpelderly ?></dd>
                </dl>
            </div>
            <div class="checkbox col_12 sub_col_0">
              <span><?php echo $this->t('House Keeping')?></span>
                  <?php echo $this->form->householdcleaning ?>
            </div>
            
            <h2><?php echo $this->t('Overseas Experience')?></h2>
            <div class="select oversea">
                <dl>
                    <dt><label><?php echo $this->t('Location')?></label><?php echo $this->t('Years of Experience')?></dt>
                    <?php
                        $country = $this->listing->yoe_country;
                        if (empty($country)) {
                            $country = array();
                        }
                        //var_dump($country);
                    ?>
                    <?php for($i = 1; $i <= 4; $i++):?>
                        <?php 
                            list($current_country, $yo) = each($country);
                            //next($country);
                        ?>
                    
                        <dd>
                        	<label>
	                            <select name="country[<?php echo $i?>]" class="country">
	                                <?php foreach(Model_Listing_Maid::getLocationPostAd() as $k => $loc):?>
	                                    <?php $selected_country = ((!empty($_POST['country'][$i]) && $_POST['country'][$i] == $k) || $k == $current_country); ?>
	                                    <option value="<?php echo $k?>" <?php if($selected_country) {echo 'selected';}?>><?php echo $loc?></option>
	                                <?php endforeach;?>
	                            </select>
                            </label>
                            <select name="yoe[<?php echo $i?>]">
                                <?php foreach(Model_Listing_Maid::getYearExperiencePostAd() as $k => $year):?>
                                    <?php 
                                    //var_dump($ctry, $yo);
                                    $selected_yo = ((!empty($_POST['yoe'][$i]) && $_POST['yoe'][$i] == $k) || (string)$k === (string)$yo); ?>
                                    <option value="<?php echo $k?>" <?php if($selected_yo) {echo 'selected';}?>><?php echo $year?></option>
                                <?php endforeach;?>
                            </select>
                        </dd>
                    <?php endfor;?>                     
                </dl>
            </div>
        <!--/div>
        <div class="property_info_more optional"-->
            <h2><?php echo $this->t('Additional Information')?></h2>
            <div class="weight text col_6">
                <label><?php echo $this->t('Weight')?></label>
                <span><?php echo $this->t('In kilograms')?></span>
                <?php echo $this->form->weight;?>
            </div>
            <div class="height text col_6">
                <label><?php echo $this->t('Height')?></label>
                <span><?php echo $this->t('In centimeters')?></span> 
                <?php echo $this->form->height;?>
            </div>

            <div class="description textarea">
                <label><?php echo $this->t('Tell Us About Yourself - Life Philosophy, Hobbies, Self Intro, References')?></label>
                <span id="counter_description2"><em>1000</em> <?php echo $this->t('characters remaining')?></span>
                <?php echo $this->form->cs_en;?>
                <?php if (!empty($_POST['cs_en'])): ?>
                    <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['cs_en'])): ?>
                      <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
                    <?php endif; ?>
                <?php endif; ?>
                <span id="info_description"><?php echo $this->t('To prevent spam, do not enter any email addresses.')?></span>
            </div>
        </div>

        <?php echo $this->Partial('/index/photo-uploader.phtml', 'listing', array('listing' => $this->listing));?>

        <div class="desc">
			<p><?php echo $this->t('To reach more people, your Ad will be automatically translated and posted in both English and Chinese.');?></p>
		</div>
		<p class="button em">
			<button type="submit" name="postyourad"><?php echo $this->t('Post Your Ad')?></button>
		</p>
		<p class="preview button">
	   <button id="review-your-ad" type="submit" name="review"><?php echo $this->t('Edit Translation')?></button>
		</p>
</fieldset>
</form>
